//
// Created by Administrator on 2023/7/29.
//
# include <iostream>

using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    bool evaluateTree(TreeNode *root) {
        // 是叶子节点
        if (root->left == nullptr and root->right == nullptr) return root->val;
        // 后序遍历
        bool leftResult = evaluateTree(root->left);
        bool rightResult = evaluateTree(root->right);
        return root->val == 2 ? leftResult | rightResult : leftResult & rightResult;
    }
};

int main() {
    TreeNode n1{2}, n2{1}, n3{3}, n4{0}, n5{1};
    n1.left = &n2;
    n1.right = &n3;
    n3.left = &n4;
    n3.right = &n5;
    Solution s;
    cout << s.evaluateTree(&n1) << endl;

}